package com.kewu.system.controller;

import com.kewu.common.global.ResponseData;
import com.kewu.system.api.entity.SysUser;
import com.kewu.system.service.SysUserService;
import com.kewu.common.global.request.PageParam;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;

/**
 * (SysUser)表控制层
 *
 * @author wangning
 * @since 2024-05-28 09:22:19
 */
@RestController
@RequestMapping("/sysUser")
@RequiredArgsConstructor
public class SysUserController {
    /**
     * 服务对象
     */
    private final SysUserService sysUserService;

    /**
     * 分页查询
     *
     * @param sysUser 筛选条件
     * @return 查询结果
     */
    @GetMapping("/page")
    public ResponseData<PageInfo<SysUser>> page(SysUser sysUser, PageParam pageParam) {
        return ResponseData.success(sysUserService.page(sysUser, pageParam));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/find/{id}")
    public ResponseData<SysUser> queryById(@PathVariable("id") Integer id) {
        return ResponseData.success(sysUserService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param sysUser 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    public ResponseData<SysUser> add(@RequestBody SysUser sysUser) {
        return ResponseData.success(sysUserService.add(sysUser));
    }

    /**
     * 编辑数据
     *
     * @param sysUser 实体
     * @return 编辑结果
     */
    @PostMapping("/update")
    public ResponseData<SysUser> edit(@RequestBody SysUser sysUser) {
        return ResponseData.success(sysUserService.update(sysUser));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @GetMapping("/delete/{id}")
    public ResponseData<Boolean> delete(@PathVariable("id") Integer id) {
        return ResponseData.success(sysUserService.delete(id));
    }

}

